/*
* Name: PinHandle.cpp
* Created by 勇 on 2022/11/16.
* Description: esp8266引脚处理
*
*/
#include "PinHandle.h"

/**
 * 控制开关引脚
 */
uint8_t switchPin[SWITCH_NUMBER] = {D7, D1, D2};

/**
 * 初始化引脚
 */
void initPin(){

    for (int i = 0; i < SWITCH_NUMBER; ++i) {
        // 设置引脚为输出模式
        pinMode(switchPin[i],OUTPUT);
        // 设置引脚为低电平
        digitalWrite(switchPin[i],LOW);
    }
    // 板载灯
    pinMode(D4,OUTPUT);
    digitalWrite(D4,LOW);
}

/**
 * 板载LED控制
 */
void ledHandle(){
    digitalWrite(D4,!digitalRead(D4));
}

/**
 * 开关处理
 * @param num
 */
void switchHandle(int mode){
    switch (mode) {
        case  WORK_MODE_SWITCH_ONE:
            digitalWrite(switchPin[0], !digitalRead(switchPin[0]));
            break;
        case  WORK_MODE_SWITCH_TOW:
            digitalWrite(switchPin[1], !digitalRead(switchPin[1]));
            break;
        case  WORK_MODE_SWITCH_THREE:
            digitalWrite(switchPin[2], !digitalRead(switchPin[2]));
            break;
    }
    // 设置发送数据到服务器
    setWorkMode(SEND_DATA_TO_SERVER);
}